package cn.kxx.serviceImpl;


import cn.kxx.exception.BusinessException;
import cn.kxx.mapper.MemberMapper;
import cn.kxx.pojo.Member;
import cn.kxx.service.MemberService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {

    @Autowired
    private MemberMapper memberMapper;

    @Override
    public Member findByTelephone(String telephone) throws BusinessException {
        return memberMapper.selectOne(new LambdaQueryWrapper<Member>().eq(Member::getPhoneNumber, telephone));


    }

    @Override
    public void add(Member member1) throws BusinessException {

        memberMapper.insert(member1);
    }

    /**
     * @描述: 查询每月的会员数
     * @参数: list
     * @返回值: list<interger></>
     * @创建人: kxx
     * @创建时间: 2023/3/2 14:52
     * @修改人和其它信息:
     */

    @Override
    public List<Integer> findMemberCountByMouth(List<String> list) throws BusinessException {

        List<Integer> list1 = new ArrayList<>();
        for (String s : list) {
            Integer count = memberMapper.selectCount(new LambdaQueryWrapper<Member>().le(Member::getRegTime, s + "-31"));

            list1.add(count);

        }
        return list1;
    }
}
